<?php
class GestionContenu {
    private $conBDD;
    public function __construct($conBDD){
        $this->conBDD=$conBDD;
    }
    public function getListeContenu($colonne="idcontenu",$WHERE=NULL){
        $query="";
        $query.="SELECT * FROM scrum_contenu";
        if($WHERE!=NULL){
            $query.=" WHERE ".  implode(" AND ", $WHERE)." ";
        }
        $res=$this->conBDD->query($query);
        $tabG=array();
        while($row = @mysql_fetch_array($res)){
            $g=new Contenu();
            $g->setIdContenu($row["idcontenu"]);
            $g->setInfo($row["info"]);
            $g->setLibelle($row["libelle"]);
            $tabG[$row[$colonne]]=$g;
        }
        return $tabG;
    }
    public function getAllTags($term){
        $query="";
        $query.="SELECT tags FROM scrum_contenu";
        $query.=" WHERE tags LIKE '%".$term."%' ";
        $res=$this->conBDD->query($query);
        $tabTags=array();
        while($row = @mysql_fetch_array($res)){
            $tmp=array();
            $tmp=explode(",",$row["tags"]);
            foreach($tmp as $val){
                if(@preg_match("/".$term."/i", $val)) $tabTags[utf8_encode($val)]=trim(utf8_encode($val));
            }
            
        }
        return $tabTags;
    }
    public function getTabHtml($tabContenu){
        $html="";
        if(sizeof($tabContenu)>0){
            foreach($tabContenu as $id=>$cont){
                $html.= "<div>";
                    $html.= "<p class='justified'>";
                        $html.= nl2br(utf8_encode($rol->getInfo()) );
                    $html.= "</p>";
                $html.= "</div>";
            }
        }
        else{
            if(isset($_GET['search_titre'])){
                $html.= "Pas de résultat(s) pour '".$_GET['search_titre']."'";
            }
            else{
                $html.= "Rien";
            }
        }
        return $html;
    }
}
?>